<?php
error_reporting(E_ALL);

// Includo Joomla
define( '_JEXEC', 1 );
define( '_VALID_MOS', 1 );
define('JPATH_BASE', dirname(__FILE__) . "/../../.." );
define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

/**
 * CREATE THE APPLICATION
 *
 * NOTE :
 */
define('_ISO','charset=utf-8');
jimport('joomla.database.database');
jimport( 'joomla.database.table' );
require_once(JPATH_BASE . '/plugins/system/legacy/dbtable.php');

require_once(JPATH_BASE . '/configuration.php');
$conf = new JConfig();

$host 		= $conf->host;
$user 		= $conf->user;
$password 	= $conf->password;
$database	= $conf->db;
$prefix 	= $conf->dbprefix;
$driver 	= $conf->dbtype;
$debug 		= $conf->debug;

$options	= array ( 'driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix );

$database =& JDatabase::getInstance( $options );

// Carico dati segnalazioni
jimport('joomla.database.database');
$query = "SELECT * FROM #__fap_report_allarm WHERE confirmed='1' AND published='1' AND report_status='1' ORDER BY report_recovery_date DESC LIMIT 2";
$database->setQuery( $query );
$data = $database->loadObjectList();

// Ciclo sui dati delle segnalazioni
$scale = '/libraries/effetticollaterali/utils/images/scale_in_canvas_img.php?img=/components/com_chronocontact/uploads/segnala_pericolo/[PHOTO]&amp;width=200&amp;height=200';
require_once(JPATH_BASE . '/administrator/components/com_google_maps_vision/google_maps_vision.class.php');

$xml = "";

foreach($data as $s) {
	$s -> report_status = ($s -> report_status > 1 ? 0 : $s -> report_status);
	$s -> report_address = str_replace("'", "`", $s -> report_address);
	
	// Aggiungo civico
	if($s -> report_number) {
		$s -> report_address .= ", " . $s -> report_number;
	}
	
	$s -> report_city = 'Napoli';
	$s -> report_state = 'Napoli';
	$s -> report_country = 'Italy';
	$s -> lat = '';
	$s -> lng = '';
	
	$xml .= "<segnalazione>\n";
	$xml .= "<address><![CDATA[" . $s -> report_address . "]]></address>\n";
	$xml .= "<city>Napoli</city>\n";
	$xml .= "<state>Napoli</state>\n";
	$xml .= "<zipcode>" . $s -> report_zip . "</zipcode>\n";
	$xml .= "<country>Italia</country>\n";
	$xml .= "<posted_by>" . $s -> name . " " . $s -> surname . "</posted_by>\n";
	$xml .= "<resolved_on>" . date("d/m/Y", strtotime($s -> report_recovery_date)) . "</resolved_on>\n";
	$xml .= "<misc><![CDATA[" . str_replace("'", "&apos;", stripslashes(strip_tags($s -> report))) . "]]></misc>\n";
	$xml .= "</segnalazione>\n";
}


header("Content-type: application/xml");
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Pragma: no-cache');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
echo "<ultime-segnalazioni>\n";
echo $xml;
echo "</ultime-segnalazioni>\n";